#include "directlight.h"

namespace GLC {

DirectLight::DirectLight(GLenum lightNo)
    :_isEnabled(false)
    ,_lightNo(lightNo)
{
    setDirection(vec3f(0, 0, 1));
    setDiffuseIntensity(0.4, 0.4, 0.4);
    setAmbientIntensity(0.1, 0.1, 0.1);
    setSpecularIntensity(0.4, 0.4, 0.4);
}

DirectLight::~DirectLight()
{
}

void DirectLight::enable() const
{
    _isEnabled = true;
    glLightfv(_lightNo, GL_POSITION, _direction);
    glLightfv(_lightNo, GL_DIFFUSE, _diffuse);
    glLightfv(_lightNo, GL_AMBIENT, _ambient);
    glLightfv(_lightNo, GL_SPECULAR, _specular);
    glEnable(_lightNo);
}

void DirectLight::disable() const
{
    _isEnabled = false;
    glDisable(_lightNo);
}

bool DirectLight::isEnabled() const
{
    return _isEnabled;
}

void DirectLight::setDirection(const vec3f &direction)
{
    _direction = vec4f(direction, 0);
    if (_isEnabled)
    {
        enable();
    }
}

void DirectLight::setDiffuseIntensity(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
    _diffuse.x = r;
    _diffuse.y = g;
    _diffuse.z = b;
    _diffuse.w = a;
    if (_isEnabled)
    {
        enable();
    }
}

void DirectLight::setAmbientIntensity(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
    _ambient.x = r;
    _ambient.y = g;
    _ambient.z = b;
    _ambient.w = a;
    if (_isEnabled)
    {
        enable();
    }
}

void DirectLight::setSpecularIntensity(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
    _specular.x = r;
    _specular.y = g;
    _specular.z = b;
    _specular.w = a;
    if (_isEnabled)
    {
        enable();
    }
}

}
